package com.example.walletdemo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.walletdemo.common.utils.ResponseResult;
import com.example.walletdemo.entity.pojo.UserWallet;
import com.example.walletdemo.entity.pojo.WalletRecord;
import com.example.walletdemo.mapper.UserWalletMapper;
import com.example.walletdemo.mapper.WalletRecordMapper;
import com.example.walletdemo.service.UserWalletService;
import com.example.walletdemo.service.WalletRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

/**
 * @Author: 包
 * @Date: 2023/2/20 22:56
 * Description:
 */
@Service
public class UserWalletServiceImpl extends ServiceImpl<WalletRecordMapper, WalletRecord> implements UserWalletService {

    @Autowired
    private UserWalletMapper userWalletMapper;

    @Override
    public ResponseResult getBalance(Long walletId, Long userId) {
        QueryWrapper<UserWallet> userWalletQueryWrapper = new QueryWrapper<>();
        userWalletQueryWrapper
                .eq("wallet_id", walletId)
                .eq("user_id", userId);
        UserWallet userWallet = userWalletMapper.selectOne(userWalletQueryWrapper);
        if (userWallet == null){
            return ResponseResult.errorResult(203,"参数错误,该账户不存在");
        }else {
            return ResponseResult.okResult(userWallet.getBalance());
        }

    }
}
